package com.dingwei.superiordiary.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.adapter.adapter.ImagePageAdapter;
import com.dingwei.superiordiary.weight.HackyViewPager;
import com.lihao.baselibrary.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * 查看大图
 */
public class PhotoDetailsActivity extends BaseActivity {

	private TextView num_text;
	private HackyViewPager pager;
	private ImagePageAdapter madapter;
	private List<String> list = new ArrayList<>();
	private int num = 1;
	private ImageView title;


	@SuppressWarnings("unchecked")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.photo_detail_layout);
		Intent intent = getIntent();
		if (intent != null) {
			list = (List<String>) intent.getSerializableExtra("img");
			num = intent.getIntExtra("position", 0);
		}
		initContror();
	}

	@Override
	protected int getContentViewId() {
		return 0;
	}

	@Override
	protected void initData() {

	}

	@Override
	protected void initView() {

	}

	@Override
	protected void initListener() {

	}

	private void initContror() {
		title = (ImageView) findViewById(R.id.back);
		title.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
				
			}
		});

		num_text = (TextView) findViewById(R.id.photo_num_tv);
		pager = (HackyViewPager) findViewById(R.id.photo_pager);
		madapter = new ImagePageAdapter(this, list);
		num_text.setText(num + 1 + "/" + list.size());
		pager.setAdapter(madapter);
		pager.setCurrentItem(num);
		pager.setOnPageChangeListener(pageChange);
	}
	OnPageChangeListener pageChange = new OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				// TODO Auto-generated method stub
				num_text.setText(position + 1 + "/" + list.size());
				num = position;
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}
	};




}
